new Vue({
  el: "#app",
  data() {
    return {
      form: {
        Data: "company_profile",
        Primary_Key: "",
        Primary_Key_Name: "Company_Profile_Name",
        isVague: true,
        page: 1, //页数
        limit: 10, //每页数据条数
      },
      tableData: [], //表格数据
      total: 1,
    };
  },
  mounted() {
    this.getList(this.form);
  },
  methods: {
    onSerach() {
      //查询方法
      this.form.page = 1;
      this.getList(this.form);
    },
    Add() {
      window.location.href = "./Add.html";
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form);
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form);
    },
    getList(data) {
      //换页方法
      let _this = this;
      $.ajax({
        type: "POST",
        // url: DomainName + "/getTableInquiryAction?token=" + $.cookie("token"),
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableNameWithOriginal",
        data: {
          Data: "company_profile", //表名
          Condition: "Row_Status =0",
        },
        // complete: function (XMLHttpRequest) {
        //   _this.loading = false
        //   if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
        //     window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
        //   }
        // },
        success: function (Result) {
          console.log(Result);

          _this.tableData = Result; //将获取的数据存到表格数据中
          _this.total = Number(Result.limit);
        },
        dataType: "json",
      });
    },
    Edit(Company_Profile_SerialNumber) {
      //修改
      sessionStorage.setItem(
        "Company_Profile_SerialNumber",
        Company_Profile_SerialNumber
      );
      window.location.href =
        "./Edit.html?Company_Profile_SerialNumber=" +
        Company_Profile_SerialNumber;
    },
    Show(Company_Profile_SerialNumber) {
      sessionStorage.setItem(
        "Company_Profile_SerialNumber",
        Company_Profile_SerialNumber
      );
      window.location.href =
        "./Show.html?Company_Profile_SerialNumber=" +
        Company_Profile_SerialNumber;
    },
    Delete(row) {
      console.log(row);
      row.Row_Status = 1;
      let lArray = new Array();
      lArray.push(row);
      let lJSONObject_company_profile = new Object();
      lJSONObject_company_profile.company_profile = lArray; //换表
      let lJSONObject_DataSet = new Object(); // Modify
      lJSONObject_DataSet.Modify = lJSONObject_company_profile; //换表
      console.log(lJSONObject_DataSet);

      // return;
      const _this = this;
      this.$confirm("警告！此操作将删除该服务, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          $.ajax({
            // url: DomainName + "/DeleteAction?token=" + $.cookie("token"),
            url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
            type: "POST",
            data: {
              Data: JSON.stringify(lJSONObject_DataSet),
            },
            // data: {
            //   TableName: "company_profile",
            //   Primary_Key: row.Company_Profile_SerialNumber,
            //   Primary_Key_Name: "Company_Profile_SerialNumber",
            //   Operation_Name: "删除公司简介",
            // },
            success: function (res) {
              if (res.Status == "success") {
                _this.getList(_this.form);
                _this.$message({
                  type: "success",
                  message: "删除成功!",
                });
              }
            },
            // complete: function (XMLHttpRequest) {
            //   if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            //     window.parent.document.location.href =
            //       absolutepath() +
            //       XMLHttpRequest.getResponseHeader("CONTENTPATH");
            //   }
            // },
          });
        })
        .catch(() => {
          this.$message({
            type: "warning",
            message: "已取消操作",
          });
        });
    },
    Status(row) {
      console.log(row);
      console.log(row.Company_Profile_Status);
      if (row.Company_Profile_Status == 1) {
        row.Company_Profile_Status = 0;
      } else if (row.Company_Profile_Status == 0) {
        row.Company_Profile_Status = 1;
      }

      let lArray = new Array();
      lArray.push(row);
      let lJSONObject_company_profile = new Object();
      lJSONObject_company_profile.company_profile = lArray; //换表
      let lJSONObject_DataSet = new Object(); // Modify
      lJSONObject_DataSet.Modify = lJSONObject_company_profile; //换表
      console.log(lJSONObject_DataSet);

      // return;
      //启用禁用
      const _this = this;
      $.ajax({
        url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
        type: "POST",
        data: {
          Data: JSON.stringify(lJSONObject_DataSet),
        },
        // data: {
        //   active: "1",
        //   inactive: "0",
        //   type: row.Company_Profile_Status == "0" ? "1" : "0",
        //   TableName: "company_profile",
        //   Primary_Key: row.Company_Profile_SerialNumber,
        //   Primary_Key_Name: "Company_Profile_SerialNumber",
        //   Value_Name: "Company_Profile_Status",
        //   Operation_Name:
        //     row.Company_Profile_Status == "0" ? "切换公司简介" : "禁用公司简介",
        // },
        success: function (res) {
          console.log(row);
          console.log(res);
          if (res.Status == "success") {
            if (row.Company_Profile_Status == 0) {
              _this.$message({
                message: "禁用成功",
                type: "success",
              });
            } else {
              _this.$message({
                message: "生效成功",
                type: "success",
              });
            }
          }
        },
        // complete: function (XMLHttpRequest) {
        //   if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
        //     window.parent.document.location.href =
        //       absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
        //   }
        // },
      });
      // }
    },
  },
});
